package com.sky.controller.admin;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(tags = "管理员店铺操作接口")
@Slf4j
@RestController
@RequestMapping("/admin/shop")
public class AdminShopController {
	//注入redis获取商店状态
	@Autowired
	RedisTemplate<String, Object> redisTemplate;

	/**
	 * 获取商店状态
	 * @return
	 */
	@ApiOperation("获取营业状态")
	@GetMapping("/status")
	public Result getStatus(){
		Integer shopStatus = (Integer) redisTemplate
										.opsForValue()
										.get(ShopStatusConstant.SHOP_STATUS);
		log.info("获取商店状态{}",shopStatus);
		return Result.success(shopStatus);
	}

	/**
	 * 设置商店状态
	 * @param status
	 * @return
	 */
	@ApiOperation("设置营业状态")
	@PutMapping("/{status}")
	@Transactional
	public Result setStatus(@PathVariable Integer status){
		redisTemplate.opsForValue().set(ShopStatusConstant.SHOP_STATUS, status);
		log.info("设置商店状态{}",status);
		return Result.success();
	}
}
